package service

import (
	"dbManager/example/dao"
	"dbManager/example/model"
	"fmt"
	"log"

	"github.com/zhuxiujia/GoMybatis"
)

type TestService struct {
	mapper dao.TestcaseMapper
}

func NewTestService(mapper dao.TestcaseMapper) TestService {
	return TestService{
		mapper: mapper,
	}
}
func (test TestService) FindAll() {
	fmt.Println(test.mapper.FindAll())
}
func (test TestService) Insert(session GoMybatis.Session, testcase model.Testcase) {
	defer func() {
		session.Commit()
	}()
	defer func() {
		if err := recover(); err != nil {
			session.Rollback()
			fmt.Println(err) // 这里的err其实就是panic传入的内容，55
		}
	}()
	_, err := test.mapper.Insert(&session, testcase)
	i := 0
	y := 10 / i
	fmt.Println(y)
	if err != nil {
		log.Println("插入错误回滚")
		session.Rollback()
	}
}
